<?php
use yii\widgets\LinkPager;
use yii\web\Session;
use app\modules\cruise\models\Member;

$this->title = '签到';

$type = isset($params['type']) ? $params['type'] : '4';
$type_v = isset($params['type_v']) ? $params['type_v'] : '';

$member = \Yii::$app->session->get('member');

$member_model = Member::find()->where(['phone'=>$member['phone'],'status'=>1])->one();

$role = $member_model['role'];


?>

<?= yii\web\View::registerCssFile("/m/css/reset.css",['depends' => 'app\assets\MuiAsset']) ?>
<?= yii\web\View::registerCssFile("/m/css/qiandao.css",['depends' => 'app\assets\MuiAsset']) ?>
<?= yii\web\View::registerCssFile("/js/layer_mobile/need/layer.css",['depends' => 'app\assets\MuiAsset']) ?>
<style type="text/css">
	.text-center{text-align: center;}	
	.customer-list{margin-bottom: 30px;margin-top:20px;}
	.left-top span{margin-right:10px;color: #000;font-weight: 300;display:inline-block;}
	.c-list{color: #000;}
	.right{padding: 10px 0px 10px 2px;}
	.iconfont{font-size: 14px;}
	.left{padding: 5px 0 5px 15px;}
	.s1{width: 20px;}
	.s2{width: 50px;}
	.btn-x{float: left;margin-bottom: 5px;margin-right: 5px;}
	.un-cancel{background-color: #106c5d!important;border: none;color: #ffffff;}
	.recover-c{background-color: #398439!important;border: none;color: #ffffff;}
	.edit{height: 40px;text-align: center;background-color: #19a58e;}
</style>

<div class="nav mui-row">
	<?php if($role == 3){ ?>
		<div class="qiandao mui-col-sm-4 mui-col-xs-4">
			<a href="/sign/sign/index">签到</a>
		</div>
		<div class="tongji mui-col-sm-4 mui-col-xs-4">
			<a href="/sign/sign/statis">统计</a>
		</div>
		<div class="edit mui-col-sm-4 mui-col-xs-4">
			<a>审核</a>
		</div>
	<?php }else{ ?> 
		<div class="qiandao mui-col-sm-6 mui-col-xs-6">
			<a>签到</a>
		</div>
		<div class="tongji mui-col-sm-6 mui-col-xs-6">
			<a href="/sign/sign/statis">统计</a>
		</div>
	<?php }?>	
	
</div>
<input type="hidden" name="_csrf" id="_csrf" value="<?=\Yii::$app->getRequest()->getCsrfToken()?>">

<div class="biaoti mui-row">
	<div class="logo mui-col-xs-3 mui-col-sm-3">
		<img src="/img/logo.png"/>
	</div>
	<div class="chaxun mui-col-xs-9 mui-col-sm-9">
		<form action="/sign/sign/cancel-list" method="get">
			<select name="type" class="select-t">
				<option value="4" <?=($type == 4) ? 'selected' :'' ;?> >姓名</option>
				<?php if($role !== 2){ ?>
				<option value="3" <?=($type == 3) ? 'selected' :'' ;?> >团号</option>
				<?php }?>
				<option value="2" <?=($type == 2) ? 'selected' :'' ;?> >护照号</option>
				<option value="1" <?=($type == 1) ? 'selected' : '';?> >手机号</option>
			</select><input type="<?=($type == 4) ? 'text' :'tel' ;?>" name="type_v" value="<?=$type_v?>" class="type_v" />
			<input type="submit" value="查询"/>
		</form>
	</div>
</div>
<div class="list">
	<ul class="customer-list" id="customer-list">
		<?php foreach($model as $customer){ ?>
		<li class="c-list mui-row">
			<div class="left  mui-col-xs-8">
				<div class="left-top">
					<div style="width: 50%;display: inline-block;">
					<span><?=$customer->group?></span>
					</div>
				</div>
				<div class="left-bottom">
					<div style="width: 50%;display: inline-block;">
					<span><?=$customer->first_name.$customer->last_name?></span>
					</div>
				</div>
				<div class="left-bottom">
					<div style="width: 50%;display: inline-block;">
					<span><?=$customer->phone?></span>
					</div>
					<span><?=$customer->passport?></span>
				</div>
				<div class="left-bottom">
					<div style="width: 50%;display: inline-block;">
					<span>衣服号码：<?=$customer->size?></span>
					</div>
					<span>衣服颜色：<?=$customer->color?></span>
				</div>
				<div class="left-bottom">
					<div style="width: 50%;display: inline-block;">
					<span>房间号：<?=$customer->roomUse->code?></span>
					</div>
					<span>培训票：<?=$customer->ticket?></span>
				</div>
			</div>
			<div class="right  mui-col-xs-4">
				<a href="tel:<?=$customer->phone?>" class="mui-btn btn-x tel"><i class="iconfont">&#xe6aa;</i>
				</a>

			
					<?php if($role == 2 || $role == 3){ ?>	
						<?php if($customer->sign == 0){ ?>
						<button type="button" class="mui-btn btn-x sign" data-id="<?=$customer->id?>" >未签到</button>
						<?php }else{ ?>
						<button type="button" class="mui-btn btn-x act" data-id="<?=$customer->id?>">已签到</button>
						<?php }?>
					<?php }?>	

					<?php if($role == 2){ //领队 ?>
						  <?php if($customer->cancel == 1){ ?>
						  <button type="button" class="mui-btn btn-x cancel" data-id="<?=$customer->id?>" >取消客人</button>
						  <?php }else if($customer->cancel == 2){ ?>
						  <button type="button" class="mui-btn btn-x un-cancel" data-id="<?=$customer->id?>" >撤回取消</button>	
						  <?php }else if($customer->cancel == 3){?>
						  <button type="button" class="mui-btn btn-x over-cancel" data-id="<?=$customer->id?>">已取消</button>
						  <?php }?>
				    <?php }?>

				    <?php if($role == 3){ //管理员 ?>
						  <?php if($customer->cancel == 1){ ?>
						  <button type="button" class="mui-btn btn-x cancel" data-id="<?=$customer->id?>" >取消客人</button>
						  <?php }else if($customer->cancel == 2){?>
						  <button type="button" class="mui-btn btn-x confirm" data-id="<?=$customer->id?>">确认取消</button>
						  <button type="button" class="mui-btn btn-x un-confirm" data-id="<?=$customer->id?>">驳回取消</button>
						  <?php }else if($customer->cancel == 3){?>
						  <button type="button" class="mui-btn btn-x over-cancel" data-id="<?=$customer->id?>">已取消</button>
						  <button type="button" class="mui-btn btn-x recover-c" data-id="<?=$customer->id?>">恢复取消</button>
						  <?php }?>

				    <?php }?>

				
				
			</div>
		</li>
		<?php }?>
		
	</ul>

	<div class="mui-content-padded text-center">
    <?= yii\widgets\LinkPager::widget(['pagination' => $pages,'lastPageLabel'=>false, 'firstPageLabel'=>false,'maxButtonCount'=>5,'activePageCssClass'=>'mui-active','disabledPageCssClass'=>'mui-disabled','nextPageLabel' => false,'prevPageLabel' => false,'options'=>['class'=>'mui-pagination']]); ?>
   </div>

</div>


<?= yii\web\View::registerJsFile("/m/js/jquery-ui.min.js",['depends' => 'app\assets\MuiAsset']) ?>
<?= yii\web\View::registerJsFile("/js/layer_mobile/layer.js",['depends' => 'app\assets\MuiAsset']) ?>

<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

 var phone = $.trim(localStorage.getItem("phone"));
 var _csrf = $("#_csrf").val();
 if(phone.length != 0){
	$.ajax({
       type: "post",
       async:false, 
       url: "/sign/member/auto-login",
       data: {'phone':phone,'_csrf':_csrf},
       success: function(res){
       	    var res = $.parseJSON(res);
            if(res.code == 0){
            	return false;
            }else if(res.code == 1){
            	window.location.reload(); 
            }
       }
	});
 }


$(".select-t").change(function(){
	var value = $(this).val();
	if(value == 4){
		$(".type_v").attr("type","text");	
	}else{
		$(".type_v").attr("type","tel");
	}
});

//签到
$("#customer-list").on("click",".sign",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 1;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/sign",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '签到失败!',skin: 'msg',time:1 });
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('sign');
	       		_self.addClass('act');
	       		_self.text("已签到");
	       	   layer.open({content: '签到成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});

//取消签到
$("#customer-list").on("click",".act",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 2;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/sign",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '取消签到失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('act');
	       		_self.addClass('sign');
	       		_self.text("未签到");
	       	   layer.open({content: '取消签到成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});


//申请取消
$("#customer-list").on("click",".cancel",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 1;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/cancel",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '取消客户失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('cancel');
	       		_self.addClass('un-cancel');
	       		_self.text("撤回取消");
	       	   layer.open({content: '申请成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});

//撤回取消
$("#customer-list").on("click",".un-cancel",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 2;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/cancel",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '撤回取消失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('un-cancel');
	       		_self.addClass('cancel');
	       		_self.text("取消客人");
	       	   layer.open({content: '撤回成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});

//确定取消
$("#customer-list").on("click",".confirm",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 1;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/confirm",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '确认取消失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('confirm');
	       		_self.addClass('over-cancel');
	       		_self.text("已取消");
	       		var un_this = $(".un-confirm[data-id="+id+"]");
	       	    un_this.removeClass('un-confirm');
	       	    un_this.addClass('recover-c');
	       	    un_this.text("恢复取消");
	       	   layer.open({content: '确认取消成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});

//驳回取消
$("#customer-list").on("click",".un-confirm",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 2;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/confirm",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '驳回取消失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('un-confirm');
	       		_self.addClass('cancel');
	       		_self.text("取消客人");
	       		$(".confirm[data-id="+id+"]").remove();
	       	   layer.open({content: '确认取消成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});

//恢复取消
$("#customer-list").on("click",".recover-c",function(){
	var _self = $(this);
	var id = _self.attr("data-id");
	var type = 3;
	$.ajax({
	   type: "get",
	   async:false, 
	   url: "/sign/sign/confirm",
	   data: {"id":id,"type":type},
	   success: function(msg){
	       if(msg == 0){
	       	   layer.open({content: '恢复取消失败!',skin: 'msg',time:1 });	
	       	   return false;
	       }else if(msg == 1){
	       		_self.removeClass('recover-c');
	       		_self.addClass('cancel');
	       		_self.text("取消客人");
	       		$(".over-cancel[data-id="+id+"]").remove();
	       	   layer.open({content: '恢复取消成功!',skin: 'msg',time:1 });
	       }

	   }
	});
});
</script>
<?php app\components\JsBlock::end() ?> 